package com.zmn.plat.admin.controller.service.tariff.citygroup;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.plat.common.exception.PlatException;
import com.zmn.plat.model.vo.service.tariff.citygroup.ServiceTariffCityGroupAddEditVO;

/**
 * 故障分组表
 *
 * @author tanbiao
 * @since 2019-11-21 18:57:24
 */
@RestController
@RequestMapping("/service/tariff/citygroup/")
@SuppressWarnings("Duplicates")
public class ServiceTariffCityGroupModifyController extends ServiceTariffCityGroupBaseController {
    private static final long serialVersionUID = -5983717525550895208L;

    /**
     * 新增修改
     *
     * @param faultGroup
     * @author tanbiao
     * @since 2019-11-21 18:57:24
     */
    @RequestMapping(value = "addEdit")
    @RequiresPermissions("/service/tariff/citygroup/detail.action")
    public ResponseDTO addEdit(HttpServletRequest request, @RequestBody ServiceTariffCityGroupAddEditVO faultGroup) {
        if (StringUtil.isBlank(faultGroup.getGroupName())) {
            return ResponseDTO.fail("分组名称不能为空");
        }
        if (CollectionUtils.isEmpty(faultGroup.getItemList())) {
            return ResponseDTO.fail("请选择城市");
        }
        try {
            faultCityGroupBService.addEdit(faultGroup, getMcStaffRealName());
            return ResponseDTO.success(Integer.toString(faultGroup.getGroupId()), "操作成功！");
        } catch (PlatException ex) {
            logger.error("新增/修改分组表失败", ex);
            return ResponseDTO.fail(ex.getMessage());
        } catch (Exception ex) {
            logger.error("新增/修改分组表失败", ex);
            return ResponseDTO.fail("操作失败！");
        }
    }

    /**
     * 删除分组
     *
     * @param groupId
     * @author tanbiao
     * @since 2019-11-21 18:57:24
     */
    @RequestMapping(value = "deleteGroup")
    @RequiresPermissions("/service/tariff/citygroup/deleteGroup.action")
    public ResponseDTO updateStatus(HttpServletRequest request, @RequestParam(value = "groupId", defaultValue = "0") Integer groupId) {
        // 删除分组同时删除明细
        Integer result = faultCityGroupBService.deleteByKey(groupId);
        return ResponseDTO.success(result, "操作成功！");
    }

}
